package com.stockz.ui.swing.charting.widget;

import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.DefaultComboBoxModel;

import com.stockz.core.util.CoreConstant.TIME_UNIT;
import com.stockz.ui.swing.charting.util.ChangeTimeUnitUtil;
import com.stockz.ui.swing.charting.view.StockChartPanel;
import com.stockz.ui.swing.widget.JComboBox;

public class TimeUnitCombobox extends JComboBox {
	private static final long serialVersionUID = 890428682284599991L;
	
	private final StockChartPanel stockChartPanel;
	
	public TimeUnitCombobox(StockChartPanel stockChartPanel1){
		super();
		this.stockChartPanel = stockChartPanel1;
		setModel(new DefaultComboBoxModel(TIME_UNIT.values()));
		setSelectedItem(TIME_UNIT.DAILY);
		
		addItemListener(new ItemListener(){
			@Override
			public void itemStateChanged(ItemEvent e) {
				if(stockChartPanel != null){
					stockChartPanel.getStockChartPanelState().setCurrentTimeUnit((TIME_UNIT)getSelectedItem());
					ChangeTimeUnitUtil.changeTimeUnit(stockChartPanel);
				}
			}
		});
	}
}
